<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="resource"></div>
    <div id="accountContainer"></div>
    <button onclick="amend()" id="button">修改密码</button>
    <!-- <%=name%> -->
    <%-name%>
</body>
<script>
    let data
    fetch('http://localhost:3200/api/getUser', { method: 'POST' }).then(res => res.json()).then(res => {
        data = res.userData
        const accountDiv = document.getElementById('accountContainer');
        accountDiv.innerHTML = `账号：${res?.userData?.[0].account ?? '<a href="http://localhost:3200/login.html">去登陆</a>'}`
        if (!res?.userData) {
            const button = document.getElementById('button');
            button.disabled = true
        }
    })
    const resourceDiv = document.querySelector('#resource')
    function tree(array,parentId=null){
        return array.filter(item=>item.parentId===parentId).map(item=>({...item,children:tree(array,item.id)}))
    }
    fetch('http://localhost:3200/api/cache', { method: 'GET' }).then(res => res.json()).then(res => {
        resourceDiv.innerHTML = `<div style="white-space:pre-wrap;color:Blue">${res.message}\n${res.timestamp}</div>`
        console.log(tree(res.linearArray))
    })
    function amend() {
        window.location = `http://localhost:3200/passwordAmend.html?account=${data[0].account}`
    } 
</script>

</html>